home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / FILES.SWG / 0067_Totally Erased files.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  2KB  |  57 lines

  1.  
  2. Program Zap;
  3.  
  4. Procedure ZapIt(FileName : String; Pattern : Char; LastPass : Boolean);
  5. Var
  6.   NumRead,
  7.   NumWritten  : Word;
  8.   Buffer      : Array[1..4096] Of Char;
  9.   BufferSize  : Word;
  10.   ZapFile     : File;
  11.   ZapFilePos  : LongInt;
  12.  
  13. Begin
  14.   BufferSize := SizeOf(Buffer);
  15.   Assign(ZapFile, FileName);
  16.   {$I-} Reset(ZapFile, 1); {$I+}
  17.   If IOResult <> 0 Then Begin
  18.     WriteLn('File not found');
  19.     Halt;
  20.   end;
  21.   Repeat
  22.     ZapFilePos := FilePos(ZapFile);
  23.     BlockRead(ZapFile, Buffer, BufferSize, NumRead);
  24.     FillChar(Buffer, BufferSize, Pattern);
  25.     Seek(ZapFile, ZapFilePos);
  26.     BlockWrite(ZapFile, Buffer, NumRead, NumWritten);
  27.   Until (NumRead = 0) Or (NumWritten <> NumRead);
  28.   Close(ZapFile);
  29.   if LastPass Then Erase(ZapFile);
  30. End;
  31.  
  32. begin
  33.   ZapIt(ParamStr(1), #005, False);  {0101}
  34.   ZapIt(ParamStr(1), #010, False);  {1010}
  35.   ZapIt(ParamStr(1), #000, False);  {0000}
  36.   ZapIt(ParamStr(1), #255, True );  {1111}
  37. end.
  38.  
  39. {
  40. Here's the comments for the above procedure:
  41.  
  42.    Get the buffer size for later use
  43.    Get the file name from the first command line parameter
  44.    Try to open the file
  45.    If there was an error opening file, show the user and exit
  46.    otherwise repeat this code
  47.      Save the current file position
  48.      Read a block of data from the file into a buffer
  49.      Fill buffer with specified bit pattern
  50.      Reset file position to where we read this block from and
  51.      write the block back to the file
  52.    until we're done or there was a conflict in the read/write size
  53.    close the file
  54.    delete the file from disk if it's the last pass
  55. }
  56.  
  57.